package org.jeeasy.system.modules.dept.domain;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonGetter;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.dromara.autotable.annotation.mysql.MysqlTypeConstant;
import org.dromara.mpe.autotable.annotation.Column;
import org.dromara.mpe.autotable.annotation.Table;
import org.jeeasy.common.core.annotation.dict.Dict;
import org.jeeasy.common.core.base.BaseEntity;
import org.jeeasy.common.core.domain.vo.BaseTree;
import org.jeeasy.system.enums.dept.OrgCategoryEnum;
import org.jeeasy.system.enums.dept.OrgTypeEnum;

import java.util.List;

/**
 * 组织机构
 *
 * @author AlpsDDJ
 * @date 2020/11/24 11:06
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@Table(value = "sys_dept", comment = "组织机构")
//@Column(comment = "组织机构")
public class SysDept extends BaseEntity<SysDept> implements BaseTree<SysDept> {

    @Column(comment = "父机构ID", length = 24)
    private String parentId;

    @Column(comment = "机构/部门名称", length = 32)
    private String deptName;

    @Column(comment = "英文名", length = 32)
    private String deptNameEn;

    @Column(comment = "缩写", length = 32)
    private String deptNameAbbr;

    @Column(comment = "排序", length = 6, decimalLength = 2)
    private Double sortNo;

    @Column(comment = "描述", length = 255)
    private String description;

    @Column(comment = "机构类别", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = OrgCategoryEnum.class)
    private Integer orgCategory;

    @Column(comment = "机构类型", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = OrgTypeEnum.class)
    private Integer orgType;

    @Column(comment = "机构编码", length = 180)
    private String orgCode;

    @Column(comment = "手机号", length = 16)
    private String mobile;

    @Column(comment = "传真", length = 16)
    private String fax;

    @Column(comment = "地址", length = 255)
    private String address;

    @Column(comment = "备注", length = 255)
    private String remark;

    @Column(comment = "启用标记", length = 1, type = MysqlTypeConstant.TINYINT, defaultValue = "1")
    @TableField(fill = FieldFill.INSERT)
    private Integer enableFlag;

    @JsonGetter
    public boolean hasChildren() {
        Integer orgType = this.getOrgType();
        return OrgTypeEnum.TOP.getValue().equals(orgType);
    }

    @TableField(exist = false)
    private List<SysDept> children;

}
